/**
 * Created by caelan on 2018/10/20.
 */

var stationType = {

  html: function (stationArray) {
    var name = {
        AllStation: '所有站',
        CountryStation: '国家站',
        Old723Station: '区域站',
        TargetStation: '指标站'
      },
      html = '<div class="pluginsDiv" id="stationPluginsDiv">';

    var options = '';
    for ( var i = 0, len = stationArray.length; i < len; i++ ) {
      if(stationArray[i] !== "AllStation" && stationArray[i] !== "TargetStation"){
          if( stationArray[i] == "CountryStation"){
              options += '<option selected value="'+ stationArray[i] +'">'+ name[stationArray[i]] +'</option>'
          }else{
              options += '<option value="'+ stationArray[i] +'">'+ name[stationArray[i]] +'</option>';
          }
      }

    }
    options += '<option value="customize">自定义</option>';

    html += '<div class="layui-form-item pluginsSingleRows">' +
      '<label class="layui-form-label">站点类型:</label>' +
      '<div class="layui-input-inline">' +
        '<select lay-filter="stationSelect" id="stationSelect">'+ options +'</select>' +
      '</div>' +
      '<div class="layui-input-inline">' +
        '<button '+ (stationArray[0] === 'customize' ? '' : 'disabled' ) +' ' +
          'class="layui-btn set-station '+ (stationArray[0] === 'customize' ? '' : 'layui-btn-disabled' ) +' layui-btn-normal layui-btn-sm">设置</button>' +
      '</div>' +
      '</div>';



    html += '</div>';
    return html;
  },
  getData: function () {
    var val = $('#stationSelect').val();
    Global.postData.staType = val === 'customize' ? 'AllStation' : val;
    /*自定义站点选择*/
    Global.postData.stations = customizeStation.selectStation;
    Global.postData.staSelectType = val === 'customize' ? 'StationSelectCustom' : 'StationSelectAll';
  },
  renderCallback: function () {
    var _this = this;
    layForm.on('select(stationSelect)', function (data) {
      /*自定义站*/
      if ( data.value === 'customize' ) {
        $('#stationPluginsDiv').find('.set-station').attr('disabled', false).removeClass('layui-btn-disabled');

        _this.openSelectStation();

      } else if(data.value === 'Old723Station' ){//区域站
          $('#stationPluginsDiv').find('.set-station').attr('disabled', true).addClass('layui-btn-disabled');
          customizeStation.selectStation = [];

          $('#historyPluginsDiv .multiOption').eq(1).click();//当为所有站清空 历史统计机的全部
      } else {
        $('#stationPluginsDiv').find('.set-station').attr('disabled', true).addClass('layui-btn-disabled');
        customizeStation.selectStation = [];

          initControlByName(Global.currElementName);//重新加载面板
      }
    });

    /*设置按钮*/
    $('#stationPluginsDiv').find('.set-station').click(function () { _this.openSelectStation(); });

  },
  /*打开站点选择弹出层*/
  openSelectStation: function () {
    layLayer.open({
      type: 1,
      title: '自定义选择站点',
      area: ['980px', 'calc(100% - 80px)'],
      btn: '确定',
      content: $('#customizeStation'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
      yes: function (ind) {
        $('#getCheckCustomizeStation').trigger('click');
        layLayer.close(ind);
      },
      success: function () {
        /*重载适应宽度*/
        // layTable.reload('customizeStationTable', {
        //   data: data,
        //   // page: {
        //   //   curr: 1 //重新从第 1 页开始
        //   // }
        // });

        // layTable.reload('customizeStationTable');
      }
    });
    /*表格重新渲染，界面宽度样式修正*/
    layTable.reload('customizeStationTable', {});
  }


};